package cn.tedu.mall.seckill.controller;

import cn.tedu.mall.common.restful.JsonPage;
import cn.tedu.mall.common.restful.JsonResult;
import cn.tedu.mall.pojo.seckill.vo.SeckillSpuDetailSimpleVO;
import cn.tedu.mall.pojo.seckill.vo.SeckillSpuVO;
import cn.tedu.mall.seckill.service.ISeckillSpuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/seckill/spu")
@Api(tags = "秒杀spu模块")
@Slf4j
public class SeckillSpuController {

    @Autowired
    private ISeckillSpuService spuService;

    @ApiOperation("分页查询秒杀spu商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "page",example = "1"),
            @ApiImplicitParam(name = "pageSize",value = "pageSize",example = "2")

    })
    @GetMapping("/list")
    public JsonResult<JsonPage<SeckillSpuVO>> listSeckillSpus(Integer page,Integer pageSize){
        JsonPage<SeckillSpuVO> jsonPage = spuService.listSeckillSpus(page, pageSize);
        return JsonResult.ok(jsonPage);
    }

    @ApiOperation("根据spuId查询detail详情")
    @ApiImplicitParam(name = "spuId",value = "spuId",example = "2")
    @GetMapping("/{spuId}/detail")
    public JsonResult<SeckillSpuDetailSimpleVO> getSeckillDetail(@PathVariable Long spuId){
        SeckillSpuDetailSimpleVO seckillSpuDetail = spuService.getSeckillSpuDetail(spuId);
        return JsonResult.ok(seckillSpuDetail);
    }

    // localhost:10007/seckill/spu/2
    @ApiOperation("根据spuId查询spu相关信息")
    @ApiImplicitParam(name = "spuId",value = "spuId",example = "2")
    @GetMapping("/{spuId}")
    public JsonResult<SeckillSpuVO> getSeckillSpuVO(@PathVariable Long spuId){
        SeckillSpuVO seckillSpuVO = spuService.getSeckillSpu(spuId);
        return JsonResult.ok(seckillSpuVO);
    }
}
